/**
 * Created by Administrator on 2016/6/16.
 */

/*function formDate(t){
    var year = t.getFullYear();
    var month = t.getMonth() + 1;
    var day = t.getDay();
    var hour = t.getHours();
    var mi = t.getMinutes();
    var result = year + '-' + month + '-' + day + '' + hour + ':' + mi ;
    return result;
}*/
/*
var petname = $.cookie('petname');
//回答
$('.questions').delegate('[question]','click',function(){
    if(petname){
        $.cookie('question',$(this).attr('question'));
        location.href = '/answer.html';
    }else{
        location.href = '/signin.html';
    }
});

$.getJSON('/questions',function(res) {     //getjson缩写的ajax请求
//console.log(res);
    //var html = '';
    //console.log(res.data);
    /!*for(var i=0;i<res.data.length;i++) {
     var q = res.data[i];
     html += '<div class="media" question="' + new Date(q.time).getTime() + '">';
     html += '<div class=media-left>';
     html += '<a>';
     html += '<img class="media-object" src="uploads/' + q.petname + '.jpg">';
     html += '</a>';
     html += '</div>';
     html += '<div class="media-body">';
     html += '<h4 class="media-heading">' + q.petname + '</h4>';
     html += q.content;
     html += '<div class=media-footer>';
     html += formDate(new Date(q.time));
     html += '</div>';
     html += '</div>';
     html += '</div>';*!/
    //将这个数据结果交给template模板文件进行处理后，再加载到html页面当中去的
    //也就是说，这个数据不是直接显示在
    //
    var html = template('question', res);
    $('.questions').html(html);
});
template.helper('ms',function(time){
    var time = new Date(time);
    return time.getTime();
});
template.helper('formatTime',function(time){
    var time = new Date(time);
    var year = time.getFullYear();
    var month = time.getMonth();
    var day = time.getData();

    var month = month < 10 ? '0' + month : month;
    var day = day < 10 ? '0' + day : day;
    return `${year}-${month}-${day}`;
});


       /!*  //遍历回答
         if (q.answers) {
             for (var j = 0; j < q.answers.length; j++) {
                 var a = q.answers[j];
                 html += '<div class="media">';
                 html += '<div class="media-body">';
                 html += '<h4 class="media-heading">' + a.petname + '</h4>';
                 html += a.content;
                 html += '<div class="media-footing">';
                 html += formDate(new Date(a.time));
                 html += '</div>';
                 html += '</div>';
                 html += '<div class="media-right">';
                 html += '<a>';
                 html += '<img class="media-object" src="uploads/' + a.petname + '.jpg">';
                 html += '</a>';
                 html += '</div>';
                 html += '</div>';
             }
         }
     }
    $('.questions').html(html);

});*!/




/!*<div class="media">
    <div class="media-left">
    <a href="#">
    <img class="media-object" src="..." alt="...">
    </a>
    </div>
    <div class="media-body">
    <h4 class="media-heading">Media heading</h4>
...
</div>
</div>*!/
*/


/**
 * Created by hama on 2016/6/16.
 */


var petname = $.cookie('petname');
//回答
$('.questions').delegate('[question]','click',function(){
    if(petname){
        $.cookie('question',$(this).attr('question'));
        location.href = '/answer.html';
    }else{
        location.href = '/signin.html';
    }
});

$.getJSON('/questions',function(res){
    //将这个数据结果交给template模板文件进行处理之后，再加载到html页面当中去的.
    //也就是说，这个数据不是直接显示在HTML页面当中的，而是通过了art-template的处理之后,
    //才显示在index.html页面中的.
    var html = template('question',res);
    $('.questions').html(html);
});

template.helper('ms',function(time){
    var time = new Date(time);
    return time.getTime();
});
template.helper('formatTime',function(time){
    var time = new Date(time);
    var year = time.getFullYear();
    var month = time.getMonth() + 1;
    var day = time.getDate();
    var month = month < 10 ? '0' + month : month;
    var day = day < 10 ? '0' + day : day;
    return `${year}-${month}-${day}`;
});
